<!DOCTYPE html>
<?php session_start(); ?>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="public/css/style.css" />
        
        
        
         <?php
                        if (isset($_GET["logout"]) && $_GET["logout"] == true) {
                            unset($_SESSION["id"]);
                            header("location:index.php");
                        }
                        ?>
        
        <?php 
            //Require your file here
            require_once 'template/Pagination.php';
            require_once 'model/works.php';
            require_once 'log.php';
            //Create global variable
            $md_works = new Works();
            $works = $md_works->select();
            $total=  count($works);
            $pagination = new Pagination();
            $page=1;
            if (isset($_GET['page'])) {
                $page = $_GET['page'];
            }
            $works = $md_works->select(null, $page);
        ?>
        
    </head>
    <body>
        
        <div class="container">
            <!-- Include header-->
            <?php include('template/header.php')?>

            <div class="content">
                <div class="pagination"><?php echo $pagination->display($total, $page); ?></div>
                <!--luot truy cap-->
                <td>Lượt truy cập</td>
                <td><b><?php echo mwriteLogs()?></b></td>
                <table class="list-works" border="1px" align="center">
                
                    <tr>
                        <td>Id</td>
                        <td>Name</td>
                        
                        <td>Image</td>
                        <td>Description</td>
<!--                        <td>Company name</td>-->
                        <td>Edit</td>
                        
                    </tr>
                <?php foreach ($works as $work):?>
                    <tr>
                        <td><?php echo $work['id'] ?></td>
                        <td><?php echo $work['name'] ?></td>
                        <td> <img src="<?php echo $work['image']; ?>"width="50px"></td>
                    
                        <td><?php echo substr($work['description'], 0, 100); ?></td>
<!--                        <td><?php echo $work['company_name'] ?></td>-->
                       <td>
                        <?php if(isset($_SESSION["id"])):?>
                                | <a href="edit.php?id=<?php echo $work['id'] ?>">Edit</a> |
                                | <a href="delete.php?id=<?php echo $work['id'] ?>">Delete</a> |
                                |<a href="view.php?id=<?php echo $work['id']?>">View</a>|
                                <?php endif;?>
                         <?php if(isset($_SESSION["id"])==NULL):?>
                                |<a href="view.php?id=<?php echo $work['id']?>">View</a>|
                                <?php endif;?>
                    </td>
                    </tr>
                    
                <?php endforeach;?>
                </table>
                
            </div>
            <!-- Include footer-->
            <?php include ('template/footer.php') ?>
        </div>
    </body>
</html>